package reflect;

import java.lang.reflect.Field;

public class PropertyUtil {
    public static void setProperty(Object obj, String propertyName, Object value) {
        Class<?> clazz = obj.getClass();
        try {
            Field declaredField = clazz.getDeclaredField(propertyName);
            declaredField.setAccessible(true);
            declaredField.set(obj,value);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Dog dog = new Dog();
        PropertyUtil.setProperty(dog,"name","牛逼");
        System.out.println(dog.getName());
    }
}
